#ifndef ANIMCONFIG_H_
#define ANIMCONFIG_H_

#include <D3DX9.h>
#include <D3dx9math.h>
#include <vector>
#include <string>
using std::vector;

#define MAX_JOINTS 25

struct TQuaternionInfo
{
	D3DXVECTOR3 scale;
	D3DXVECTOR3 pos;
	D3DXQUATERNION rotation;
};

struct TKeyFrame
{
	float fKeyTime;
	D3DXMATRIX local;
	D3DXMATRIX world;
	TQuaternionInfo tFrame;
};

struct TAnimBone
{
	char szName[128];
	unsigned int unBoneIndex;
	vector<TKeyFrame> vKeyFrames;
};

struct TJoint
{
	std::string name;
	int parentIndex;
	TJoint* parent;
	bool dirty;
	D3DXMATRIX localMat;
	D3DXMATRIX worldMat;
	std::vector<TJoint*> childrenIndex;
	
	TJoint() { dirty = true; parent = NULL; }

	void Update()
	{
		dirty = true;

		for(unsigned int i = 0; i < childrenIndex.size(); ++i)
			childrenIndex[i]->Update();
	}

	D3DXMATRIX GetWorldMat()
	{
		if(dirty)
		{
			if(parent)
			{
				D3DXMATRIX parentMat = parent->GetWorldMat();
				D3DXMatrixMultiply(&worldMat, &localMat, &parentMat);
			}
			else
				worldMat = localMat;

			dirty = false;
		}
		
		return worldMat;
	}

	D3DXMATRIX GetLocalMat() { return localMat; }
};

struct TInfluence
{
	unsigned int jointIndex;
	float weight;
	std::string name;
};

#endif